import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

// https://leetcode-cn.com/problems/partition-labels/
// 763. 划分字母区间

class Solution {
    public List<Integer> partitionLabels(String s) {
        int[] letter = new int[26];
        Arrays.fill(letter, -1);

        char[] c = s.toCharArray();
        for (int i = 0; i < c.length; i++) {
            letter[c[i] - 'a'] = i;
        }

        List<Integer> result = new ArrayList<Integer>();
        int edge = Integer.MIN_VALUE;
        int last = 0;
        for (int i = 0; i < c.length; i++) {
            if (letter[c[i] - 'a'] > edge) {
                edge = letter[c[i] - 'a'];
            }
            if (edge == i) {
                result.add(i - last + 1);
                last = i + 1;
            }
        }

        return result;

    }
}

